package com.txazo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.txazo.dao.BaseDao;
import com.txazo.domain.User;
import com.txazo.service.UserService;

/**
 * 用户模块Service实现
 * 
 * @author txazo
 * @since 1.0
 * 
 */
@Service("userService")
@Transactional
public class UserServiceImpl implements UserService {

	@Autowired
	private BaseDao baseDao;

	@Override
	public User login(User user) {
		List<User> list = baseDao.findAll(
				"from User where username = ? and password = ?", User.class,
				new Object[] { user.getUsername(), user.getPassword() });
		if (list.size() == 1) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public User register(User user) {
		List<User> list = baseDao.findAll("from User where username = ?",
				User.class, user.getUsername());
		if (list.size() == 0) {
			baseDao.save(user);
			return user;
		}
		return null;
	}

}
